<?php
function edp_is_empty_string( $string ) {
    if( is_array($string) ) {
        if( count($string) == 0 )
            return true;
        else
            return false;
    }
    if( !isset( $string ) ||  is_null($string) || strlen( trim($string) ) == 0 )
        return true;
    return false;
}


function edp_db_input( $string ) {
    //mysql_escape_string has been DEPRECATED as of PHP 5.3.0
    //and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

    //GetDB();

    if(get_magic_quotes_gpc()) {
        $string =  mysql_real_escape_string( stripslashes($string) );
    }
    else {
        $string = mysql_real_escape_string( $string );
    }

    /*
		// prevent from xss attack by using the script in the content
		$string = preg_replace( '/&/', "" , $string );
		$string = preg_replace( '/</', "\&lt;" , $string );
		$string = preg_replace( '/\\\\/', "" , $string );
    */
    // prevent using the comment notation in MySQL
    // double '-' makes a sql comment
    //$string = str_replace( '\r\n', "\r\n", $string );

    return $string;
}

function GetDBLogger() {
    $logFileName = "error.log";

    $DBLogger = new EDPLogger( $logFileName, DB_LOG_FILE_PATH, DB_LOG_HISTORY_FILE_PATH, 1 );
    return $DBLogger;
}

function GetAuditLogger( $logFileName = "audit.log" ) {
    $DBLogger = new EDPLogger( $logFileName, DB_LOG_FILE_PATH, DB_LOG_HISTORY_FILE_PATH, 1 );
    return $DBLogger;
}

function GetLogger() {

    $logFileName = "error.log";

    $Logger = new EDPLogger( $logFileName, LOG_FILE_PATH, LOG_HISTORY_FILE_PATH );
    return $Logger;
}

function edp_error_handler ( $errno, $errstr, $errfile, $errline, $errcontext ) {

    $error =  "Error_handler: " . $errno . ':' . $errstr . ':' . $errfile. ':' . $errline . ':' . $errcontext;
    $Logger = GetLogger();
    $Logger->error( $error );

    return false;
}

function exception_handler( $exception ) {

    if( !($exception instanceof DBException) ) {
        $error =  "Exception: " . $exception->getMessage();
        $Logger = GetLogger();
        $Logger->error( $error );
    }
}

?>
